<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #app {
        width: 100%;
        height: 100%;
      }
      #app img {
        width: 100%;
        height: 100%;
      }
    </style>
  </head>
  <body>
    <div id="app"></div>
    <script>
      function loadImg(url) {
        return new Promise((resolve, reject) => {
          let img = document.createElement("img");
          let app = document.querySelector("#app");
          app.appendChild(img);
          img.onload = () => {
            resolve(img);
          };
          img.onerror = () => {
            let err = new Error(`图片加载错误 ${url}`);
            reject(err);
          };
          img.src = url;
        });
      }
      const url1 = "https://img2.mukewang.com/60e528a0000148e217920764.jpg";
      const url2 = "https://img.mukewang.com/60e3ecd700016f9c17920764.jpg";
      loadImg(url1)
        .then((img1) => {
          console.log(img1.width);
        })
        .then((img2) => {
          return loadImg(url2);
        })
        .then((img2) => {
          console.log(img2);
        });
      // .catch((err) => {
      //   console.log(err);
      // });
    </script>
  </body>
</html>
